import * as insVue from 'vue'
import ts, { ModuleKind, ModuleResolutionKind, ScriptTarget } from 'typescript'

export function getTsToJs(code: string): string {
  code = ts.transpileModule(code, {
    compilerOptions: {
      target: ScriptTarget.ESNext,
      module: ModuleKind.ESNext,
      moduleResolution: ModuleResolutionKind.NodeNext,
      strict: true,
      noLib: false,
      noEmit: true,
      skipLibCheck: true,
      isolatedModules: true,
      forceConsistentCasingInFileNames: true,
      allowSyntheticDefaultImports: true,
      strictFunctionTypes: false,
      baseUrl: '.',
      allowJs: true,
      sourceMap: true,
      esModuleInterop: true,
      resolveJsonModule: true,
      noUnusedLocals: true,
      noUnusedParameters: true,
      experimentalDecorators: true,
      lib: ['dom', 'esnext'],
      noImplicitAny: false,
      removeComments: true,
    },
  }).outputText

  return code.replaceAll('\n', '') ?? ''
}

export function getInsBwUtils(options: Record<string, any>) {
  const bwUtils = {}
  return Object.assign(bwUtils, insVue, options)
}
